package tests.dao;

import static org.junit.Assert.*;
import java.sql.SQLException;
import java.util.LinkedList;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import person.crud.dao.PersonDAO;
import person.model.Person;

@ContextConfiguration(locations = { "classpath:mvc-dispatcher-servlet.xml" })
@RunWith(SpringJUnit4ClassRunner.class)
public class TestPersonDAO
{
    @Autowired
    PersonDAO personDAO;

    @Test
    public void testAdd() throws SQLException
    {
	Person p = new Person(1, 23, "Vasia", "Pupkin", "M");
	assertTrue(personDAO.add(p));
    }

    @Test
    public void testGetAll() throws SQLException
    {
	LinkedList<Person> ls = personDAO.getAll();
	for (Person p : ls)
	{
	    System.out.println(p);
	}
    }

    @Test
    public void testUpdate() throws SQLException
    {
	Person p = new Person(1, 23, "Vasia", "Pupkin", "M");
	personDAO.update(p);

    }

    @Test
    public void testContextSearch2() throws SQLException
    {

	Person p = new Person(3, 20, "Vasia", "Pupkin", "M");
	assertTrue(personDAO.getCombined(p).get(0).equals(p));

    }

}
